<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cart_model extends CI_Model{
	
	function retrieve_products(){  
    	//TODO migriera bort denna
		$query = $this->db->get('products');
        return $query->result_array();
    }    
		
    function store_product(){
    	$id = $this->input->post('product_id');
    	$quantity = $this->input->post('quantity');
    	$query = $this->db->query("SELECT * FROM products WHERE id=".$id);
    	
    	if($query->num_rows > 0)
    	{
	    	foreach($query->result() as $row)
	    	{
	    		$data = array(
	    		'id' => $id,
	    		'qty' => $quantity,
	    		'price' => $row->price,
	    		'name' => $row->name);
				
	    		/*
	    		var_dump($id);
	    		var_dump($quantity);
	    		var_dump($row->price);
	    		var_dump($row->name);
	    		*/
	    		
	    		
	    		$this->cart->insert($data);
	    		//var_dump($this->cart->contents());
	    		return true;
	    	}
    	}
    	else
    	{
    		return false;
    	}
    }
    
    function destroy_cart(){
    	$this->cart->destroy();
    }
}
